package cn.itcast.java.list;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Author itcast
 * Date 2021/10/10 16:12
 * 使用增强for循环遍历输出 int数组的值
 * for(元素的数据类型 数据 ： 集合变量){ 数据操作 }
 */
public class ListDemo02 {
    public static void main(String[] args) {
        List<Integer> arr = new ArrayList<>();
        //
        arr.add(1);
        arr.add(3);
        arr.add(5);
        arr.add(7);

        for(int e : arr){
            System.out.println(e);
        }

        // iter itli
        for (Integer i : arr) {
            System.out.println(i);
        }

        // itli => iterator list
        for (int i = 0; i < arr.size(); i++) {
            Integer integer =  arr.get(i);

        }

        // itar  => iterator array
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            System.out.println(args);
        }

        //数组存储 Student 类型
        List<Student> stus = new ArrayList<>();
        stus.add(new Student("A",20));
        stus.add(new Student("B",23));
        for (Student student : stus) {
            System.out.println(student);
        }

        //链表存储 Student 类型
        List<Student> stuList = new LinkedList<>();
        stus.add(new Student("A",20));
        stus.add(new Student("B",23));
        for (Student student : stus) {
            System.out.println(student);
        }
    }

    public static class Student{
        private String name;
        private int age;

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }
}
